#include "unp.h"

void dg_cli(int fd,struct sockaddr* addr, socklen_t addrlen);

void client()
{
  int fd;
  struct sockaddr_in servaddr;

  fd = socket(AF_INET,SOCK_DGRAM,0);
  memset(&servaddr,0,sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htons(INADDR_ANY);
  servaddr.sin_port = htons(10086);

  dg_cli(fd,(sockaddr*)&servaddr, sizeof(servaddr));
  shutdown(fd,SHUT_WR);
  close(fd);
}

void dg_cli(int fd,struct sockaddr* addr, socklen_t addrlen)
{
  int n;
  char sendline[4096],recvline[4096];

  while (fgets(sendline,sizeof(sendline),stdin) != NULL)
  {
    int snd = sendto(fd,sendline,strlen(sendline),0, addr,addrlen);
    n = recvfrom(fd,recvline,sizeof(recvline),0,NULL,NULL);
    recvline[n] = 0;
    fputs(recvline,stdout);
  }
}

int main(int argc, char **argv) {
  client();
  return 0;
}
